// SINGULARITY HTML5 GAME ENGINE
// -----------------------------
// Copyright(c) 2013 by Codenova.pl

define(['./Core', './Static/EventStatic'], function (Core, EventStatic) {
    var Stage = function(id, dimensions, ui) {
        this.Elements = [];
        this.Height = dimensions.Height;
        this.Id = id;
        this.Ui = ui;
        this.Width = dimensions.Width;
    };

    Stage.prototype = {
        constructor: Stage,

        Create: function(id, dimensions, ui) {
            "use strict";

            return new Stage(id, dimensions, ui);
        },

        Initialize: function() {
            var _i, _length;

            // Check for beforeRender event
            if(typeof this.BeforeRender !== 'undefined') {
                // We have beforeRender event, perform specified
                // action
                EventStatic.PerformBeforeRender(this.BeforeRender);
            }

            // Set dimensions for auto
            (this.Width == 'auto') ? this.Width = window.innerWidth : null;
            (this.Height == 'auto') ? this.Height = window.innerHeight : null;

            // Draw stage canvas
            Core.DrawCanvas(this.Id, this.Width, this.Height);

            // Attach UI for this stage
            this.Ui.Initialize(this.Id);

            // Get context
            this.Canvas = document.getElementById(this.Id);
            this.Context = this.Canvas.getContext('2d');

            // Initialize stage objects
            for(_i = 0, _length = this.Elements.length - 1; _i <= _length; _i = _i + 1) {
                this.Elements[_i].Add(this.Canvas, this.Context);
            }
        },

        Register: function(el) {
            this.Elements.push(el);
        }
    };

    return Stage.prototype.Create;
});